﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using Microsoft.ReportingServices;

namespace studentmanagementdemo
{
    public partial class frmsinhvienreport : Form
    {
        public frmsinhvienreport()
        {
            InitializeComponent();
        }

        private void frmsinhvienreport_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet1.vw_sinhvienreport' table. You can move, or remove it, as needed.
            this.vw_sinhvienreportTableAdapter.Fill(this.dataSet1.vw_sinhvienreport);
            // TODO: This line of code loads data into the 'dataSet1.vw_sinhvien_lop' table. You can move, or remove it, as needed.
            this.vw_sinhvien_lopTableAdapter.Fill(this.dataSet1.vw_sinhvien_lop);

            this.reportViewer1.RefreshReport();
            this.reportViewer2.RefreshReport();

            for (int i = 1990; i <= 2015; i++)
            {
                cbofromyear.Items.Add(i);
                cbotoyear.Items.Add(i);
            }
            cbofromyear.SelectedItem = 1990;
            cbotoyear.SelectedItem = DateTime.Now.Year;
            SetReportParameter();
            reportViewer2.RefreshReport();
        }

        private void SetReportParameter()
        {
            ReportParameter[] parameters = new ReportParameter[2];

            parameters[0] = new ReportParameter("FromYear");
            parameters[0].Values.Add(cbofromyear.SelectedItem.ToString());

            parameters[1] = new ReportParameter("ToYear");
            parameters[1].Values.Add(cbotoyear.SelectedItem.ToString());

            reportViewer2.LocalReport.SetParameters(parameters);
        }

        private void btnreport_Click(object sender, EventArgs e)
        {
            SetReportParameter();
            reportViewer2.RefreshReport();
        }
    }
}
